package com.company;

/**
 * @author zhf
 * @date 2022/1/21
 */
//给你二叉树的根结点 root ，请你将它展开为一个单链表：
public class treeToLine {

    public void flatten(TreeNode root) {
        if (root == null) {
            return;
        }
        TreeNode temp = new TreeNode();
        flatten(root.left);
        flatten(root.right);
        //采用后序遍历
        temp = root.right;
        root.right = root.left;
        root.left = null;
        while (root.right != null) {
            root = root.right;
        }
        root.right = temp;
    }
}
